<?php
include("../include/config.inc.php");
include("userlogincheck.php");

$s=$_GET["s"];
$sm = $_SESSION['session_random'];
if($s<>$sm || $s==''){	
	echo "<script>alert('参数非法！');location.href='set.php';</script>";
	exit;
}

$todo=$_REQUEST["todo"];
if(isset($todo) && $todo=="todo"){	
	$mobile = $_POST['mobile'];
	$smscode = $_POST['smscode'];
	$code = $_POST['code'];
	$verify = $_SESSION['session_verify'];
	$sms = $_SESSION['session_smscode'];
	
	if($code==""){
		echo "<script>alert('请输入验证码！');history.back(-1);</script>";
		exit;
	}
	if($code<>$verify){
		echo "<script>alert('请输入正确的验证码！');history.back(-1);</script>";
		exit;
	}
	if($mobile==""){
		echo "<script>alert('请输入手机号码！');history.back(-1);</script>";
		exit;
	}
	if($smscode==""){
		echo "<script>alert('请输入手机短信动态码！');history.back(-1);</script>";
		exit;
	}
	if($smscode<>$sms){	
		echo "<script>alert('手机短信验证码输入不正确！');history.back(-1);</script>";
		exit;
	}else{	
		$sql="update ".tableprefix."member set member_mobile='$mobile' where member_id='$userid'";
		$db->query($sql);
		if(!$db->error()){
			echo "<script>alert('手机号码修改成功');location.href='set.php';</script>";
		}else{
			echo "<script>alert('数据库出错！');location.href='index.php';</script>";
		}
	}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>修改手机号码 - 订戏会</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=9,Chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="stylesheet" type="text/css" href="../css/public.css">
<link rel="stylesheet" type="text/css" href="../css/publish.css">
<style type="text/css">
<!--
.form-item .code-box .code{position:absolute;top:0px;right:0px;z-index:1;}
.form-item .code-box .code img{float:right;width:100%;height:50px;overflow:hidden;}
.form-item .code-box{width:118px;height:28px;overflow:hidden;line-height:28px;position:absolute;top:10px;right:0;z-index:1;background:#009900;border-radius:5px;margin-right:10px;}
.form-item .code-box .btn{text-indent:0px;font-size:14px;outline:medium;background:none;border:0;color:#FF0000;width:108px;left:0px;color:#FFFFFF;text-align:center;padding:0px 5px;}
-->
</style>
<script type="text/javascript" src="../js/jquery.js"></script>
<script language="javascript">
	function get_mobile_code(){
        $.post('sms.php', {mobile:jQuery.trim($('#mobile').val()),send_code:jQuery.trim($('#code').val()),smstype:jQuery.trim($('#smstype').val())}, function(msg) {
            alert(jQuery.trim(unescape(msg)));
			if(msg=='短信发送成功'){
				RemainTime();
			}
        });
	};
	var iTime = 59;
	var Account;
	function RemainTime(){
		document.getElementById('zphone').disabled = true;
		var iSecond,sSecond="",sTime="";
		if (iTime >= 0){
			iSecond = parseInt(iTime%60);
			iMinute = parseInt(iTime/60)
			if (iSecond >= 0){
				if(iMinute>0){
					sSecond = iMinute + "分" + iSecond + "秒";
				}else{
					sSecond = iSecond + "秒";
				}
			}
			sTime=sSecond;
			if(iTime==0){
				clearTimeout(Account);
				sTime='获取手机验证码';
				iTime = 59;
				document.getElementById('zphone').disabled = false;
			}else{
				Account = setTimeout("RemainTime()",1000);
				iTime=iTime-1;
			}
		}else{
			sTime='没有倒计时';
		}
		document.getElementById('zphone').value = sTime;
	}	
</script>
</head>

<body>
<form action="" method="post" name="publishForm" id="publishForm">
<input name="todo" type="hidden" value="todo">
<input name="smstype" id="smstype" type="hidden" value="mobilechange">
<div class="mod-form">
	<div class="form-group">		
		<div class="form-item">
			<label>新号码</label>
			<input type="text" maxlength="11" id="mobile" name="mobile">
		</div>
		<div class="form-item" style="position:relative;">
			<label>验证码</label>
			<input id="code" name="code" type="text" placeholder="请输入验证码" maxlength="4">
            <span class="code" style="position:absolute;top:0px;right:0;"><img id="imgCode" src="../include/verify.php" alt="请输入验证码"></span>
		</div>
		<div class="form-item" style="position:relative;">
			<label>动态码</label>
			<input id="smscode" name="smscode" type="text" placeholder="请输入验证码" maxlength="6">
			<span class="code-box"><input id="zphone" type="button" value=" 获取手机验证码 " onClick="get_mobile_code();" class="btn"></span>
		</div>
	</div>
</div>
<div class="form-button"><input name="s" type="submit" id="s" value="确定修改"></div>
</form>

<div id="bottom"></div>

<footer id="bar-fixed">
	<a href="../" class="tab-item"><i class="icon-tabbar bar-home"></i>首页</a>
	<a href="../category.php" class="tab-item"><i class="icon-tabbar bar-message"></i>分类</a>
	<a href="../publish/" class="tab-item"><i class="icon-tabbar bar-publish"></i>发起</a>	
	<a href="../user/" class="tab-item active"><i class="icon-tabbar bar-user2"></i>我</a>
</footer>
</body>
</html>